package com.yuqian.JavaSe.socket;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

import com.yuqian.JavaSe.util.date.TimeUtil;

public class SeverSocketTest {
	public static void main(String[] args) throws IOException, InterruptedException {
		
		System.out.println("服务端注册服务:-------------");
		//新建serversocket，向9999端口注册服务
		ServerSocket serverSocket = new ServerSocket(9999);
		
		System.out.println("服务端等待连接:------------");
		//监听客户端的练就请求
		Socket server = serverSocket.accept();
		System.out.println("服务端连接客户端:----------");
		
		String msg="客户端：你好";
		
		System.out.println("服务端有事停了一下");
		
	
		PrintWriter pw = new PrintWriter(server.getOutputStream());
		
		pw.write(msg);
		System.out.println("当前时间"+TimeUtil.getCurrentTime());
		System.out.println("服务端向客户端发送消息:++"+msg);
		pw.flush();
		
		pw.close();
		Thread.sleep(10000);
		//
		server.close();
		serverSocket.close();
	}
}
